package TCP_test1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class SendMassage {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 10086);


        Scanner scanner = new Scanner(System.in);
        //获取输出流
        OutputStream os = socket.getOutputStream();
        /*
        String str = "你好";
        os.write(str.getBytes());
         */
        //写入数据
        while (true) {
            System.out.println("请输入要发送的内容:");
            String str = scanner.nextLine() ;
            if ("886".equals(str)) {
                break;
            }
            os.write(str.getBytes());//转换为字节数组
        }
        /*
        socket.shutdownOutput();
        //获取输入流
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        //读取数据
        int b;
        while((b=br.read())!=-1){
            System.out.print((char)b);
        }
         */

        //关闭资源
        socket.close();

    }
}
